package com.server.common.security.code.thread;

import java.util.HashMap;
import java.util.Map;

public class ThreadLocalHeaderUtils {

    private static final ThreadLocal<Map<String,String>> threadLocal = new ThreadLocal<>();

    /**
     * 添加头
     * @author LXC
     * @date 2023/2/3 13:43
     */
    public static void addHeader(String key,String value){
        getMap().put(key,value);
    }

    /**
     * 获取头
     * @author LXC
     * @date 2023/2/3 13:43
     */
    public static String getHeader(String key){
        return getMap().get(key.toLowerCase());
    }

    /**
     * 获取头
     * @author LXC
     * @date 2023/2/3 13:43
     */
    public static Map<String, String> getMap(){
        if(null == threadLocal.get()){
            threadLocal.set(new HashMap<>());
        }
        return threadLocal.get();
    }

    /**
     * 获取头
     * @author LXC
     * @date 2023/2/3 13:43
     */
    public static void setMap(Map<String, String> map){
        threadLocal.set(map);
    }

    /**
     * 删除threadLocal
     * @author LXC
     * @date 2023/2/3 13:43
     */
    public static void remove(){
        threadLocal.remove();
    }
}
